﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WHC.Security.Entity;
using Cls_Business;


namespace CKNetFrameWork
{
    public partial class Frm_Login : Form
    {
       // private LSY.BLL.LSY_AgentTab m_bllAccounts_Users = new LSY.BLL.LSY_AgentTab();
        public Dictionary<string, FunctionInfo> FunctionDict = new Dictionary<string, FunctionInfo>();

        public Frm_Login()
        {
            InitializeComponent();

        }

        private void buttonLogin_Click(object sender, EventArgs e)
        {
            if (this.comboBoxOrderPerson.Text == "")
            {
                this.errorProvider1.SetError(this.comboBoxOrderPerson, "用户名称不能为空！");
                return;
            }
            else
            {
                this.errorProvider1.SetError(this.comboBoxOrderPerson, "");
            }

       
         
            string strPass = this.textBox_password.Text;

            string identity = WHC.Security.BLL.BLLFactory<WHC.Security.BLL.User>.Instance.VerifyUser(this.comboBoxOrderPerson.Text, strPass, Guid.NewGuid().ToString());

            //DataSet dsLogin = m_bllAccounts_Users.GetUserInfoByLoginInfo(this.comboBoxOrderPerson.Text, strPass);
            if (!string.IsNullOrEmpty(identity))
            {
                UserInfo info = WHC.Security.BLL.BLLFactory<WHC.Security.BLL.User>.Instance.GetUserByName(this.comboBoxOrderPerson.Text);
                GlobalControl.m_nLoginUserId = info.ID;
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("用户名或密码错误,请重新输入！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.textBox_password.Text = "";

                return;
            }
           
        }

        private void buttonExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void Frm_Login_Load(object sender, EventArgs e)
        {
           
            List<UserInfo> userList = WHC.Security.BLL.BLLFactory<WHC.Security.BLL.User>.Instance.GetAll();
            this.comboBoxOrderPerson.Items.Clear();
            foreach (UserInfo info in userList)
            {
                this.comboBoxOrderPerson.Items.Add(info.Name);
            }

        }

        private void textBox_username_TextChanged(object sender, EventArgs e)
        {
            //this.textBox_username.Focus();
        }

        private void Frm_Login_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void textBox_username_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                buttonLogin_Click(this, null);
        }

        private void comboBoxOrderPerson_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                buttonLogin_Click(this, null);
        }

        private void textBox_password_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                buttonLogin_Click(this, null);
        }
    }
}
